<template>
	<view class="page">		
		
		<view class="completed-comment">
			<view class="completed-comment-card" v-for="(completedComment, completedCommentIndex) of list" :key="completedCommentIndex">
				<view class="completed-comment-desc">
					<image class="product-image" :src="completedComment.headimg" mode=""></image>
					<view class="product-comment-desc">
						<view class="completed-comment-title">
							<text class="completed-comment-title-text">{{completedComment.username}}</text>
						</view>
						<view class="completed-comment-rate">
							<text class="completed-comment-rate-text">评分</text>
							<uni-rate :value="Number(completedComment.goods_rank)" :size="rateSize" :activeColor="rateConfig.starActivecolor" disabled></uni-rate>
						</view>
					</view>
				</view> 
				<view class="completed-comment-content">
					<text class="completed-comment-content-text">{{completedComment.content}}</text>
				</view>
				<view class="completed-comment-images" v-if="completedComment.photos && completedComment.photos.length>0">
					<view class="completed-comment-thumb" v-for="(image,imageIndex) of completedComment.photos" :key="imageIndex"><image :src="image" mode="widthFix" class="image-thumb"></image></view>
				</view>
			</view>
		</view>
		<uni-load-more :status="loadMoreStatus"></uni-load-more>
	</view>
</template>

<script>
	import data from '@/data/comment/comment-goods.js';
	import initConfig from '@/mixins/comment/comment-list.js';
	
	export default {
		mixins: [initConfig],
		data() {
			return {
				currentTitleTabIndex: 0,
				default_headimg:"https://img.alicdn.com/bao/uploaded/i4/O1CN01UNhIXf1xR6rrjmX2X_!!0-rate.jpg_110x10000Q50s50.jpg_.webp",
				
				list: [],
				loadMoreStatus : "more",
				pageData:{
					last_page:1,
					total:1
				},
				postData:{
					current_page:1,
					per_page:10,
					page:1,
					id:1,
				},
			}
		},
		computed: {
			rateSize() {
				return this.toPx(this.rateConfig.starSize);
			},
		},
		async onLoad(option) {
			const completedCommentListData = data.completedCommentList();
			
			this.list = await completedCommentListData;
			
			this.postData.id = option.id || 0;
			
		},
		methods: {
			toPx(value) {
				const result = /(\d+\.?\d*)(\w+)/.exec(value);
				if ('rpx' === result[2].trim()) {
					return uni.getSystemInfoSync().screenWidth * Number(result[1]) / 750;
				} else if('px' === result[2].trim()) {
					return Number(result[1]);
				} else {
					throw new TypeError(`${value}单位格式不正确`);
				}
			}
		},
	}
</script>

<style lang="scss" scoped>
	
	.title-tab-bar {
		/* #ifndef APP-PLUS-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		justify-content: space-around;
		
		// border-top-left-radius: $uni-border-radius-base;
		// border-top-right-radius: $uni-border-radius-base;
		background-color: $uni-bg-color;
		
		position: sticky;
		/* #ifndef APP-PLUS-NVUE */
		top: var(--window-top);
		z-index: 1;
		/* #endif */
	}
	.title-tab-bar-item {
		padding-top: $uni-spacing-row-base;
		padding-bottom: $uni-spacing-row-base;
	}
	.title-tab-bar-item-text {
		font-size: $uni-font-size-base;
	}
	.title-tab-bar-item-text-selected {
		font-size: $uni-font-size-base;
		font-weight: bold;
	}
	
	// 未评论
	.uncompleted-comment{
		
	}
	.no-comment {
		/* #ifndef APP-PLUS-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
		
		background-color: $uni-bg-color;
	}
	.no-comment-icon {
		width: $uni-icon-size-mx;
		height: $uni-icon-size-mx;
		
		margin-top: $uni-spacing-row-mx;
		margin-bottom: $uni-spacing-row-base;
	}
	.no-comment-text {
		font-size: $uni-font-size-lg;
		color: $uni-text-color-grey;
	}
	
	// 已评论
	.completed-comment {
		
	}
	.completed-comment-card {
		border-radius: $uni-border-radius-base;
		background-color: $uni-bg-color;
		
		margin-bottom: $uni-spacing-row-base;
		padding-left: $uni-spacing-col-lg;
		padding-right: $uni-spacing-col-lg;
		padding-top: $uni-spacing-row-lg;
	}
	.completed-comment-desc {
		/* #ifndef APP-PLUS-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		align-items: center;
	}
	.product-image {
		width: $uni-icon-size-lg;
		height: $uni-icon-size-lg;
		
		border-radius: $uni-border-radius-circle;
	}
	.product-comment-desc {
		flex: 1;
		margin-left: $uni-spacing-col-base;
	}
	.completed-comment-title {
		margin-bottom: $uni-spacing-row-sm;
	}
	.completed-comment-title-text {
		font-size: $uni-font-size-sm;
		color: $uni-text-color-grey;
		
		/* #ifndef APP-PLUS-NVUE */
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
		overflow: hidden;
		/* #endif */
		
		/* #ifdef APP-PLUS-NVUE */
		text-overflow: ellipsis;
		lines: 1;
		/* #endif */
	}
	.completed-comment-rate {
		/* #ifndef APP-PLUS-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		align-items: center;
	}
	.completed-comment-rate-text {
		font-size: $uni-font-size-sm;
		margin-right: $uni-spacing-col-base;
	}
	
	.completed-comment-content {
		margin-top: $uni-spacing-row-base;
	}
	.completed-comment-content-text {
		font-size: $uni-font-size-sm;
	}
	
	.additional-comment {
		/* #ifndef APP-PLUS-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		
		margin-top: $uni-spacing-row-base;
	}
	.additional-comment-text {
		font-size: $uni-font-size-mi;
	}
	.additional-comment-btn {
		border-width: 0.5px;
		border-style: solid;
		border-color: $uni-border-color;
		border-radius: 10000px;
		
		/* #ifndef APP-PLUS-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		align-items: center;
		
		padding-left: $uni-spacing-col-lg;
		padding-right: $uni-spacing-col-lg;
		padding-top: $uni-spacing-row-sm;
		padding-bottom: $uni-spacing-row-sm;
		
	}
	.additional-comment-btn-text {
		font-size: $uni-font-size-sm;
	}
	.completed-comment-images{
		/* #ifndef APP-PLUS-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		flex-wrap: wrap;
		align-items:center;
		margin-top: $uni-spacing-row-base;
	}
	.completed-comment-images .completed-comment-thumb:nth-child(5n){
		margin-right: 0;
	}
	.completed-comment-thumb{
		width:122rpx;
		margin: 0 20rpx 20rpx 0;
	}
	.image-thumb{
		width:122rpx;
	}
</style>